package com.zhai.cloud.starter.quartz.job;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @package: com.tcsl.zhai-cloudun.quartz.job
 * @author: Created by 张清泉
 * @create-datetime: 2019/7/30 0030 19:34
 */
@Component
@DisallowConcurrentExecution
public class JobDemo extends QuartzJobBean {

    @Override
    protected void executeInternal(JobExecutionContext content) throws JobExecutionException {

        // 获取参数
        JobDataMap jobDataMap = content.getJobDetail().getJobDataMap();
        System.out.println(Thread.currentThread().getName() + "="+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "jobName:" + jobDataMap.get("jobName") + "===:" + jobDataMap.get("jobGroupName"));

        // 业务逻辑 ...
        System.out.println(Thread.currentThread().getName() + "   下一次执行时间: " + content.getTrigger().getNextFireTime());
    }
}
